<?php
	require_once "GalleryView.php";
	require_once "GalleryModel.php";
	require_once "Login/LoginModel.php";
	//
	class GalleryController{
		//	
		public function DoControl(Database $db){
			
			$gal_view = new GalleryView();
			$gal_model = new GalleryModel();
			$log_model = new LoginModel($db);
			$gal_message = GalleryView::GAL_NO_MESSAGE;
			//
			if ($log_model->IsLoggedIn() == true){
				//
				if ($gal_view->TriedToSubmit()){
					//
					if ($gal_model->CheckFileType($gal_view->Files()) == false){
						$gal_message = $gal_view->GetMessage(GalleryView::GAL_WRONG_FILE_TYPE);
					//
					}else if($gal_model->DoesExist($gal_view->Files()) == false){						
						$gal_message = $gal_view->GetMessage(GalleryView::GAL_PHOTO_EXISTS);
					//
					}else{
						$gal_model->SavePhoto($gal_view->Files());
						$gal_message = $gal_view->GetMessage(GalleryView::GAL_SUBMIT_SUCCESS);
					} 
				}		
				return $gal_view->DoUploadBox($log_model->GetUser(), $gal_message) . $gal_view->DoGallery();
			}
		}
	}
?>